/**
 * COPYRIGHT© KMTC 2007
 * This software is the proprietary information of Korea Marine Transport Co.LTD
 * 
 * Revision History
 * Author			Date		Description
 * ------			----		-----------
 * KIMJUHEE@wees.co.kr		
 */
package kr.or.javacafe.common.util;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author codeguru
 *
 */
public class AutoCompleteUtil {

	private List names;
	
	private AutoCompleteUtil(List listOfNames){
		this.names = listOfNames;
	}
	
	public static AutoCompleteUtil getInstance(List listOfNames){
		return new AutoCompleteUtil(listOfNames);
	}
	
	public List findNames(String prefix){
		String prefixUpper = prefix.toUpperCase();
		
		List<String> matches = new ArrayList<String>();
		
		Iterator<String> iter = names.iterator();
		while( iter.hasNext() ){
			String name = iter.next();
			if( name.toUpperCase().startsWith(prefixUpper) ){
				matches.add(name);
			}
		}
		
		return matches;
	}
	
}
